home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio / Spectro / Source / WaterfallView.m < prev   
Text File  |  1994-05-06  |  4KB  |  169 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "WaterfallView.h"
  5. #import <appkit/appkit.h>
  6. #import <appkit/PrintInfo.h>
  7.  
  8. double wf_back_ground = 0.0/3.0, wf_draw_gray = 3.0/3.0, wf_marker_gray = 1.0/3.0;
  9. double wf_deltax,wf_deltay,current_plot,wf_length,wf_ynorm,total_plots;
  10. int lastPosition,memoryElements;
  11. float *memoryData;
  12. BOOL wf_not_first_time;
  13.  
  14. @implementation WaterfallView
  15.  
  16. - setup: (int) numPlots length: (int) numPoints;
  17. {
  18.     wf_deltax = frame.size.width * 0.2 / (numPlots + 2);
  19.     wf_deltay = frame.size.height  / (numPlots + 2);
  20.     wf_length = numPoints;
  21.     wf_ynorm = [plotHeight floatValue] / (numPlots + 2);
  22.     total_plots = numPlots;
  23.     current_plot = numPlots - 1;
  24.     if (numPlots*numPoints!=memoryElements)    {
  25.         free(memoryData);
  26.     memoryElements = numPlots*numPoints;
  27.     memoryData = (float *) malloc (memoryElements*4);
  28.     }
  29.     [self clear];
  30.     return self;
  31. }
  32.  
  33. - drawNext: (float *) f;
  34. {
  35.     int i,incr,memoryOffset;
  36.     double xstep,xoffs,yoffs,ymax,max=0.0;
  37.     xstep = frame.size.width * 0.8 / wf_length;
  38.     ymax = wf_ynorm * frame.size.height;
  39.     xoffs = current_plot * wf_deltax;
  40.     yoffs = current_plot * wf_deltay + 2.0;
  41.     incr = 0.8 * wf_length / frame.size.width;
  42.     [self lockFocus];
  43.     [self setOpaque: TRUE];
  44.     PSsetlinewidth(0.1);
  45.     PSsetgray(wf_back_ground);
  46.     PSmoveto(xoffs,0.0);
  47.     PSlineto(xoffs,f[0] * ymax + yoffs);
  48.     memoryOffset = current_plot*wf_length;
  49.     memoryData[memoryOffset] = f[0];
  50.     for (i=1;i<wf_length;i++) {
  51.         memoryData[memoryOffset+i] = f[i];
  52.     if (f[i]>max) max = f[i];
  53.     if (incr==0)    {
  54.         PSlineto((double) i * xstep + xoffs,max * ymax + yoffs);
  55.         max = 0.0;    
  56.     }
  57.     else if ((i%incr)==0)    {
  58.         PSlineto((double) i * xstep+ xoffs,max * ymax + yoffs);
  59.         max = 0.0;
  60.     }
  61.     }
  62.     PSlineto((double) i * xstep+ xoffs,0.0);
  63.     PSlineto(xoffs,0.0);
  64.     PSfill();
  65.     PSstroke();
  66.     PSflushgraphics();
  67.     PSsetgray(wf_draw_gray);
  68.     PSmoveto(xoffs,f[0] * ymax + yoffs);
  69.     for (i=1;i<wf_length;i++) {
  70.     if (f[i]>max) max = f[i];
  71.     if (incr==0)    {
  72.         PSlineto((double) i * xstep + xoffs,max * ymax + yoffs);
  73.         max = 0.0;    
  74.     }
  75.     else if ((i%incr)==0)    {
  76.         PSlineto((double) i * xstep+ xoffs,max * ymax + yoffs);
  77.         max = 0.0;
  78.     }
  79.     }
  80.     PSlineto((double) i * xstep+ xoffs,yoffs);
  81.     PSlineto((double) i * xstep + wf_deltax+ xoffs,yoffs);
  82.     PSstroke();
  83.     PSflushgraphics();
  84.     [self unlockFocus];
  85.     current_plot -= 1;
  86.     return self;
  87. }
  88.  
  89. - placeTickAt: (int) position;
  90. {
  91.     int i;
  92.     lastPosition = position;
  93.     [self lockFocus];
  94.     [self setOpaque: TRUE];
  95.     PSsetlinewidth(0.1);
  96.     PSsetgray(wf_back_ground);
  97.     for (i=0;i<total_plots;i++)    {
  98.         PSmoveto(frame.size.width,wf_deltay * i + 2.0);
  99.         PSlineto(frame.size.width - (total_plots - i) * wf_deltax ,wf_deltay * i + 2.0);
  100.     }
  101.     PSstroke();
  102.     PSflushgraphics();
  103.     PSsetgray(wf_draw_gray);
  104.     PSmoveto(frame.size.width,wf_deltay * position + 2.0);
  105.     PSlineto(frame.size.width - (total_plots - position) * wf_deltax ,wf_deltay * position + 2.0);
  106.     PSstroke();
  107.     PSflushgraphics();
  108.     [self unlockFocus];
  109.     return self;
  110. }
  111.  
  112. - clear
  113. {
  114.     [self lockFocus];
  115.     [self setOpaque: TRUE];
  116.     PSsetgray(wf_back_ground);
  117.     PSrectfill(0.,0.,bounds.size.width,bounds.size.height);
  118.     PSstroke();
  119.     PSflushgraphics();
  120.     [self unlockFocus];
  121.     return self;
  122. }
  123.  
  124. - printMyPSCode:sender
  125. {
  126.  
  127.     int i;
  128.     [[[[[NXApp printInfo] setOrientation:NX_PORTRAIT andAdjust:YES]
  129.         setHorizCentered:YES]
  130.             setVertCentered:YES]
  131.                 setMarginLeft:0.0
  132.                 right:0.0
  133.                 top:0.0
  134.                 bottom:0.0];
  135.     
  136.     if (wf_back_ground == 0.0/3.0)    {
  137.     NXRunAlertPanel("Too much black ink for the printer.",
  138.     "I'm going to reverse my colors,\
  139.      From now on this view will show reverse.",NULL,NULL,"OK"); 
  140.           wf_back_ground = 3.0/3.0;
  141.       wf_draw_gray = 0.0/3.0;
  142.       wf_marker_gray = 2.0/3.0 ;
  143.         [self setup:total_plots length: wf_length];
  144.     for (i=total_plots-1;i>=0 ;i--)    
  145.         [self drawNext:&memoryData[i * (int) wf_length]];
  146.     [self placeTickAt: lastPosition];
  147.     }
  148.     [[self window] printPSCode: sender];    
  149.     return self;      
  150. }
  151.  
  152. - drawSelf: (NXRect *) r : (int) n 
  153. {
  154.     int i;
  155.     if (wf_not_first_time)   {
  156.         [self setup:total_plots length: wf_length];
  157.     for (i=total_plots-1;i>=0 ;i--)    
  158.         [self drawNext:&memoryData[i * (int) wf_length]];
  159.     [self placeTickAt: lastPosition];
  160.     }
  161.     else    {
  162.        [self clear];
  163.     wf_not_first_time = TRUE;
  164.     }
  165.     return self;
  166. }
  167.     
  168. @end
  169.